/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
#ifndef OBS_PLUGIN_CONSTANTS_H
#define OBS_PLUGIN_CONSTANTS_H
#include <cstdlib>
namespace OBSPlugin {
    // used for resource access
    const std::string RESOURCE_NATIVE_FILE_TYPE  = "native";
    const std::string RESOURCE_VOLUME_TYPE       = "volume";

    constexpr uint32_t RETRYTIMES3 = 3;

    constexpr int PROGRESS0 = 0;
    constexpr int PROGRESS50 = 50;
    constexpr int PROGRESS100 = 100;

    constexpr uint32_t ONE_MINUTE = 60;

    constexpr uint32_t BACKUP_REPORT_CIRCLE_TIME_IN_SEC = 120;

    constexpr int EXECUTE_SUBTASK_MONITOR_DUR_IN_SEC = 20;
    constexpr int GENERATE_SUBTASK_MONITOR_DUR_IN_SEC = 10;
    constexpr int SUBTASK_WAIT_FOR_SCANNER_READY_IN_SEC = 1;

    const std::string JOB_CTRL_PHASE_ALLOWLOCALNODE = "AllowBackupInLocalNode";
    const std::string JOB_CTRL_PHASE_CHECKBACKUPJOBTYPE = "CheckBackupJobType";
    const std::string JOB_CTRL_PHASE_PREJOB = "PrerequisiteJob";
    const std::string JOB_CTRL_PHASE_GENSUBJOB = "GenerateSubJob";
    const std::string JOB_CTRL_PHASE_EXECSUBJOB = "ExecuteSubJob";
    const std::string JOB_CTRL_PHASE_POSTJOB = "PostJob";

    const std::string SUBJOB_TYPE_TEARDOWN_JOBNAME = "ObsBackup_Teardown";
    const std::string SUBJOB_TYPE_COPYMETA_JOBNAME = "ObsBackup_CopyMeta";
    const std::string SUBJOB_TYPE_CREATE_SUBJOB_JOBNAME = "ObsBackup_CreateSubJob";
    const std::string SUBJOB_TYPE_ZERO_BACKUP_JUDGE_JOBNAME = "ObsBackup_ZeroBackupJudge";
    const std::string SUBJOB_TYPE_PREFIX_SCAN_JOBNAME = "ObsBackup_PrefixScan";
    const std::string SUBJOB_TYPE_SCAN_TEARDOWN_JOBNAME = "ObsBackup_ScanTeardown";
    constexpr auto BACKUP_COPY_METAFILE = "/backup-copy-meta.json";
    constexpr auto BACKUP_JOBCNT_METAFILE = "_backup-jobcnt-meta.json";
    constexpr auto BACKUP_JOBSTAT_DIR = "/backup-job/backup/stats/";
    constexpr auto RESTORE_JOBSTAT_DIR = "/backup/stats/";

#ifdef WIN32
    const std::string  dir_sep = "\\";
    const std::string METAFILE_ZIP_NAME = "metafile.zip";
#else
    const std::string  dir_sep = "/";
    const std::string METAFILE_TAR_NAME = "metafile.tar";
    const std::string METAFILE_ZIP_NAME = "metafile.tar.gz";
#endif
    const std::string METAFILE_PARENT_DIR = "filemeta";

    constexpr int REPORTSLEEPTIME = 1;
    constexpr uint32_t REPORT_INTERVAL = 90;
    constexpr uint32_t MAXBUFFERCNT = 10;
    constexpr uint32_t MAXBUFFERSIZE = 10 * 1024;
    constexpr uint32_t MAXERRORFILES = 10;

    constexpr int EXECEPTION_RETRY_TIMES = 15;
    constexpr int MIDDLE_EXECEPTION_RETRY_TIMES = 5;
    constexpr int EXECEPTION_RETRY_INTERVAL = 20;
    constexpr int NORMAL_RETRY_TIMES = 4;
    constexpr int MIDDLE_NORMAL_RETRY_TIMES = 2;
    constexpr int NORMAL_RETRY_INTERVAL = 20;

    constexpr int ONE_GB = 1024 * 1024 * 1024;
    constexpr int HALF_GB = ONE_GB / 2;
    constexpr int SCAN_CTRL_FILE_TIMES_SEC = 5;
    constexpr int SCAN_CTRL_MAX_ENTRIES_FULL_BACKUP = 100000;
    constexpr int SCAN_CTRL_MAX_ENTRIES_INCBKUP = 10000;
    constexpr uint32_t SCAN_CTRL_MIN_ENTRIES_FULL_BKUP = 100000;
    constexpr uint32_t SCAN_CTRL_MIN_ENTRIES_INC_BKUP = 10000;
    constexpr uint32_t SCAN_CTRL_MAX_QUEUE_SIZE = 10000;
    constexpr uint32_t PROGRESS_COMPLETE = 100;
    constexpr uint32_t MAX_OPEN_DIR_REQ_COUNT = 4000;
    constexpr uint32_t SLEEP_TEN_SECONDS = 10;
    const std::string META = "meta";
    const std::string SCAN = "scan";
    const std::string CTRL = "ctrl";
    const std::string DIRCACHE_FILE_NAME = "dircache";
    const std::string BACKUP = "backup";
    const std::string RESTORE = "restore";
    const std::string DELETE_CTRL_PREFIX = "delete";
    const std::string CONTROL_CTRL_PREFIX = "control";
    /*
    0 - replace exsisting files & directories
    1 - Ignore exsisting files
    2 - only replace the files that are older than restore files
    */
    const std::string REPLACE_POLICY_REPLACE_EXSISTING_FILESNFOLDERS   = "0";
    const std::string REPLACE_POLICY_IGNORE_EXSISTNG_FILES             = "1";
    const std::string REPLACE_POLICY_REPLACE_ONLY_IF_OLDER             = "2";

    constexpr uint32_t SUBJOB_TYPE_ANY = 0;
    constexpr uint32_t SUBJOB_TYPE_SETUP_PHASE = 1;
    constexpr uint32_t SUBJOB_TYPE_PREFIX_SCAN_PHASE = 2;
    constexpr uint32_t SUBJOB_TYPE_SCAN_TEARDOWN_PHASE = 3;
    constexpr uint32_t SUBJOB_TYPE_DATACOPY_COPY_PHASE = 4;
    constexpr uint32_t SUBJOB_TYPE_DATACOPY_DELETE_PHASE = 5;
    constexpr uint32_t SUBJOB_TYPE_TEARDOWN_PHASE = 6;
    constexpr uint32_t SUBJOB_TYPE_COPYMETA_PHASE = 7;
    constexpr uint32_t SUBJOB_TYPE_ZERO_BACKUP_JUDGE_PHASE = 8;
    constexpr uint32_t SUBJOB_TYPE_CREATE_SUBJOB_PHASE = 9;

    constexpr uint32_t SUBJOB_TYPE_SETUP_PHASE_PRIO = 10;
    constexpr uint32_t SUBJOB_TYPE_PREFIX_SCAN_PHASE_PRIO = 20;
    constexpr uint32_t SUBJOB_TYPE_SCAN_TEAR_DOWN_PHASE_PRIO = 30;
    constexpr uint32_t SUBJOB_TYPE_CREATE_SUB_JOB_PRIO = 40;
    constexpr uint32_t SUBJOB_TYPE_DATACOPY_COPY_PHASE_PRIO = 40;
    constexpr uint32_t SUBJOB_TYPE_DATACOPY_DELETE_PHASE_PRIO = 50;
    constexpr uint32_t SUBJOB_TYPE_COPYMETA_PHASE_PRIO = 40;
    constexpr uint32_t SUBJOB_TYPE_TEARDOWN_PHASE_PRIO = 70;
    constexpr uint32_t SUBJOB_TYPE_ZERO_BACKUP_JUDGE_PRIO = 80;

    constexpr uint32_t SUBJOB_TYPE_AGGREGATE_BASE_PRIO = 1000;

    constexpr uint32_t SUBJOB_TYPE_DATACOPY_HARDLINK_PHASE = 100; // need remove, reserve for restore compilation
    constexpr uint32_t SUBJOB_TYPE_DATACOPY_DIRMTIME_PHASE = 100; // need remove

    // deploy type
    const std::string X8000_DEPLOY_TYPE = "d0";
    const std::string X6000_DEPLOY_TYPE = "d1";
    const std::string X3000_DEPLOY_TYPE = "d2";
    const std::string ANTI_RANSOMWARE_DEPLOY_TYPE = "d4";
    const std::string SECURITY_MACHINE_DEPLOY_TYPE = "d5";
    
    const std::string XML_CONFIG_FILE = "/DataBackup/ProtectClient/ProtectClient-E/bin/xmlcfg";
    const std::string XML_READ_TYPE = XML_CONFIG_FILE + " read System deploy_type";
    const std::string RDADMIN_BASH = "su - rdadmin -s /bin/sh -c ";
}
#endif // OBS_PLUGIN_CONSTANTS_H
